com.cete.dynamicpdf
Class Attached


Example: The following example shows how to use an artifact.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;
import java.io.FileNotFoundException;
 
public class MyClass{
      public static void main(String args[]){
          
          // Create a PDF Document
          Document document = new Document();

          // Specify document as a tagged PDF
          document.setTag(new TagOptions());
         
          // Create a page and add it to the document
          Page page = new Page();
          document.getPages().add(page);
          try{
          // Create a background image
          BackgroundImage backgroundImage = new BackgroundImage("[PhysicalPath]/MyImage.jpg");
          
          Attached attached = new  Attached(com.cete.dynamicpdf.Edge.LEFT,com.cete.dynamicpdf.Edge.BOTTOM,com.cete.dynamicpdf.Edge.RIGHT,com.cete.dynamicpdf.Edge.TOP);
          // Create an artifact
          Artifact artifact = new  Artifact(ArtifactType.BACKGROUND,attached); 
        
          // Add bounding box to the artifact
          artifact.setBoundingBox(new BoundingBox(page.getDimensions().getEdge().getLeft(),page.getDimensions().getEdge().getBottom(),page.getDimensions().getEdge().getRight(), page.getDimensions().getEdge().getTop()));
        
          // Tag the background image with the artifact
          backgroundImage.setTag(artifact);
          
          // Add the background image to the page
          page.getElements().add(backgroundImage);   
          }
          catch(FileNotFoundException ex1) {
            System.err.println("Image file not found :"+ex1);
        }
          //Save the PDF
          document.draw("[PhysicalPath]/MyDocument.pdf");
      }
}